﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace BaGiaDanhCuop
{
    public class BackgoundMove
    {
        public int state;

        public Texture2D road, roadnight;
        public Texture2D cloud;

        public Texture2D sky_day;
        public Texture2D sky_afternoon;
        public Texture2D sky_night;

        public Texture2D bg_day_1;
        public Texture2D bg_day_2;
        public Texture2D bg_day_3;

        public Texture2D bg_afternoon_1;
        public Texture2D bg_afternoon_2;
        public Texture2D bg_afternoon_3;

        public Texture2D bg_night_1;
        public Texture2D bg_night_2;
        public Texture2D bg_night_3;

        public Vector2 bg_move_1;
        public Vector2 bg_move_2;
        public Vector2 bg_move_3;
        public Vector2 roadmove;

        public BackgoundMove(int state, Texture2D day1, Texture2D day2, Texture2D day3, 
            Texture2D after1, Texture2D after2, Texture2D after3, Texture2D night1, Texture2D night2, Texture2D night3, 
            Texture2D road, Texture2D roadnight, Texture2D sky_day, Texture2D sky_after, Texture2D sky_night, Texture2D cloud)
        {
            bg_move_1 = new Vector2(0, 20);
            bg_move_2 = new Vector2(0, 70);
            bg_move_3 = new Vector2(0, 140);
            roadmove = new Vector2(0, 400);

            this.sky_afternoon = sky_after;
            this.sky_day = sky_day;
            this.sky_night = sky_night;

            this.bg_afternoon_1 = after1;
            this.bg_afternoon_2 = after2;
            this.bg_afternoon_3 = after3;

            this.bg_day_1 = day1;
            this.bg_day_2 = day2;
            this.bg_day_3 = day3;

            this.bg_night_1 = night1;
            this.bg_night_2 = night2;
            this.bg_night_3 = night3;

            this.road = road;
            this.roadnight = roadnight;
            this.cloud = cloud;

            this.state = state;
        }

        public void Update(float delta)
        {
            bg_move_1.X -= 60 * delta;
            if (bg_move_1.X < -bg_day_1.Width)
            {
                bg_move_1.X = 0;
            }
            
            bg_move_2.X -= 80 * delta;
            if (bg_move_2.X < -bg_day_2.Width)
            {
                bg_move_2.X = 0;
            }

            bg_move_3.X -= 100 * delta;
            if (bg_move_3.X < -bg_day_3.Width)
            {
                bg_move_3.X = 0;
            }

            roadmove.X -= 100 * delta;
            if (roadmove.X < -road.Width)
            {
                roadmove.X = 0;
            }
        }

        public void Draw(SpriteBatch batch)
        {
            //Debug.WriteLine("background: " + state);
            if (state == GamePage.DAY)
            {
                batch.Draw(sky_day, new Vector2(0, 0), Color.White);
                batch.Draw(cloud, new Vector2(0, 0), Color.White);
                batch.Draw(bg_day_1, bg_move_1, Color.White);
                batch.Draw(bg_day_1, new Vector2(bg_move_1.X + bg_day_1.Width, 20), Color.White);
                batch.Draw(bg_day_2, bg_move_2, Color.White);
                batch.Draw(bg_day_2, new Vector2(bg_move_2.X + bg_day_2.Width, 70), Color.White);
                batch.Draw(bg_day_3, bg_move_3, Color.White);
                batch.Draw(bg_day_3, new Vector2(bg_move_3.X + bg_day_3.Width, 140), Color.White);
                batch.Draw(road, roadmove, Color.White);
                batch.Draw(road, new Vector2(roadmove.X + road.Width, 400), Color.White);
            }
            else if (state == GamePage.AFTERNOON)
            {
                batch.Draw(sky_afternoon, new Vector2(0, 0), Color.White);
                batch.Draw(cloud, new Vector2(0, 0), Color.White);
                batch.Draw(bg_afternoon_1, bg_move_1, Color.White);
                batch.Draw(bg_afternoon_1, new Vector2(bg_move_1.X + bg_day_1.Width, 20), Color.White);
                batch.Draw(bg_afternoon_2, bg_move_2, Color.White);
                batch.Draw(bg_afternoon_2, new Vector2(bg_move_2.X + bg_day_2.Width, 70), Color.White);
                batch.Draw(bg_afternoon_3, bg_move_3, Color.White);
                batch.Draw(bg_afternoon_3, new Vector2(bg_move_3.X + bg_day_3.Width, 140), Color.White);
                batch.Draw(road, roadmove, Color.White);
                batch.Draw(road, new Vector2(roadmove.X + road.Width, 400), Color.White);
            }
            else if (state == GamePage.NIGHT)
            {
                batch.Draw(sky_night, new Vector2(0, 0), Color.White);
                batch.Draw(cloud, new Vector2(0, 0), Color.White);
                batch.Draw(bg_night_1, bg_move_1, Color.White);
                batch.Draw(bg_night_1, new Vector2(bg_move_1.X + bg_day_1.Width, 20), Color.White);
                batch.Draw(bg_night_2, bg_move_2, Color.White);
                batch.Draw(bg_night_2, new Vector2(bg_move_2.X + bg_day_2.Width, 70), Color.White);
                batch.Draw(bg_night_3, bg_move_3, Color.White);
                batch.Draw(bg_night_3, new Vector2(bg_move_3.X + bg_day_3.Width, 140), Color.White);
                batch.Draw(roadnight, roadmove, Color.White);
                batch.Draw(roadnight, new Vector2(roadmove.X + road.Width, 400), Color.White);
            }
        }
    }
}
